package com.ruoyan.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @Package: com.ruoyan.conifg
 * @ClassName: LocaleResolver
 * @Author: ruoyan1998
 * @CreateTime: 2021/5/16 10:52
 * @Description:
 */
public class InterLocaleResolver implements LocaleResolver
{

    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest)
    {
        //获取请求中的语言参数
        String language = httpServletRequest.getParameter("language");

        Locale locale = null;

        //如果参数携带了国际化参数
        if(language != null)
        {
            //将参数字符串信息分割
            String[] split = language.split("_");

            locale = new Locale(split[0],split[1]);
        }
        else
        {
            //无参数则使用默认配置
            locale = Locale.getDefault();
        }

        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale)
    {

    }
}
